#ifndef _ROB_I2C_BUS_MASTER_H
#define _ROB_I2C_BUS_MASTER_H

#include <WProgram.h>
#include <avr/io.h>

#define I2C_RCV_BUF_LEN 8

#define I2C_TIMEOUT_CYCLES 100


#define I2C_ERROR_NONE 1
#define I2C_ERROR_TIMEOUT 0
#define I2C_ERROR_LOCKED 0


#define I2C_IDLE 0
#define I2C_WAITING_FOR_ACK 1
#define I2C_ACK_RECEIVED 2


class Ci2cBusMaster {

public:
  void Begin(void);
  void reset(void);
  uint8_t available(void);
  uint8_t send(uint8_t adr, uint8_t len, uint8_t withAckLen, uint8_t * buffer);
  uint8_t update(void);
  uint8_t ackReceived(uint8_t adr, uint8_t ackLen);
  uint8_t * getAck(void);


private:
  uint8_t _requestedAdr;
  uint8_t _requestedAckLen;
  uint8_t _locked;
  uint8_t _rcvBuffer[I2C_RCV_BUF_LEN];
  uint8_t _cycles;
};



extern Ci2cBusMaster I2cBusmaster;




#endif // _ROB_I2C_BUS_MASTER_H

